<?php
namespace app\index\controller;
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods:POST,GET");

use app\common\controller\HomeBase;

use think\Db;

class Guakao extends HomeBase
{
	protected function _initialize(){
		parent::_initialize();
	}

	/**
	*挂靠添加预留信息       
	**/
	public function informationAdd()
	{
		$id = $_POST['id'];
		//接收参数
		$reservedName = htmlspecialchars($_POST['name']);
		$reservedPhone = htmlspecialchars($_POST['phone']);

		//判断该手机号是否预留过
		$number = Db('reserved')->where('nav_id',$id)->where('reservedPhone',$reservedPhone)->find();
		if ($number) {
			$this->apiError('您已申请,请耐心等待');
			die;
		}

		$create_time = date('Y-m-d H:i:s',strtotime('now'));
		$data = [
			'classifyID' => $id,
			'nav_id' => $id,
			'reservedName' => $reservedName,
			'reservedPhone' => $reservedPhone,
			'reservedDate' => $create_time
		];
		$add = Db('reserved')->insert($data);
		if($add){
			//添加成功之后返回公司的电话号码
			$phoneList = Db('system')->select();
			$value = unserialize($phoneList[0]['value']);
			$arr[] = $value['site_phone'];
			$this->apiSuccess($arr,'添加成功');
		}else{
			$this->apiError('添加失败,请重试');
		}
	}
}